

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.ico">
  <link rel="icon" href="/img/favicon.ico">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="叶尘的技术升级小木屋">
  <meta name="author" content="叶尘">
  <meta name="keywords" content="">
  
  <title>17、异常（Exception） - 叶尘的技术升级小木屋</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.7.2/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->

  
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/shubiao.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/gundongtiao.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/daziyanse.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/bynotes/texiao/source/css/toubudaziji.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"www.yechen-blog.cn","root":"/","version":"1.8.11","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>YECHEN</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-qrcode"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/playlist/">
                <i class="iconfont icon-music"></i>
                音乐
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-books"></i>
                链接
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/">
                    
                    主题博客
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/docs/guide/">
                    
                    配置指南
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/docs/icon/">
                    
                    图标用法
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://www.bilibili.com">
                    
                    哔哩哔哩
                  </a>
                
              </div>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/banner.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="17、异常（Exception）">
              
            </span>

            
              <div class="mt-3">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-author" aria-hidden="true"></i>
      叶尘
    </span>
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-09-13 22:19" pubdate>
        星期一, 九月 13日 2021, 10:19 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2.5k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      32
       分钟
    </span>
  

  
  
    
      <!-- LeanCloud 统计文章PV -->
      <span id="leancloud-page-views-container" class="post-meta" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="leancloud-page-views"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">17、异常（Exception）</h1>
            
            <div class="markdown-body">
              <h3 id="17-1-异常的基本概念"><a href="#17-1-异常的基本概念" class="headerlink" title="17.1 异常的基本概念"></a>17.1 异常的基本概念</h3><h4 id="17-1-1-异常信息"><a href="#17-1-1-异常信息" class="headerlink" title="17.1.1 异常信息"></a>17.1.1 异常信息</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>        <span class="hljs-keyword">int</span> r = <span class="hljs-number">10</span> / <span class="hljs-number">0</span>;<br>        System.out.println(r);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>以上程序运行后已出现异常</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java">Exception in thread <span class="hljs-string">&quot;main&quot;</span> java.lang.ArithmeticException: / by zero<br>	at Test01.main(Test01.java:<span class="hljs-number">3</span>)<br></code></pre></td></tr></table></figure>

<p>**java 是一门很完善的语言，提供了异常的处理方式，当程序出现了不正常的情况，JVM 虚拟机就会把异常信息打印在控制台，供程序员参考，==增加程序的健壮性==**。</p>
<h4 id="17-1-2-异常以什么形式存在"><a href="#17-1-2-异常以什么形式存在" class="headerlink" title="17.1.2 异常以什么形式存在"></a>17.1.2 异常以什么形式存在</h4><p><strong>==异常在 java 中以类的形式存在，每一个异常类都可以创建异常对象。==</strong> </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java">NumberFormatException numberFormatException = <span class="hljs-keyword">new</span> NumberFormatException(<span class="hljs-string">&quot;数字格式化异常&quot;</span>);<br>System.out.println(numberFormatException);<span class="hljs-comment">// 输出：java.lang.NumberFormatException: 数字格式化异常</span><br><br>ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException = <span class="hljs-keyword">new</span> ArrayIndexOutOfBoundsException(<span class="hljs-string">&quot;数组下标越界异常&quot;</span>);<br>System.out.println(arrayIndexOutOfBoundsException);<span class="hljs-comment">// 输出：java.lang.ArrayIndexOutOfBoundsException: 数组下标越界异常</span><br></code></pre></td></tr></table></figure>

<p>异常类对应现实生活：</p>
<p><strong>丢失钱包（是一个异常类）</strong></p>
<p><strong>2008年，8月8日，小明的钱包丢了（是一个异常对象）</strong></p>
<h3 id="17-2-异常的分类"><a href="#17-2-异常的分类" class="headerlink" title="17.2 异常的分类"></a>17.2 异常的分类</h3><h4 id="17-2-1-异常的层次结构"><a href="#17-2-1-异常的层次结构" class="headerlink" title="17.2.1 异常的层次结构"></a>17.2.1 异常的层次结构</h4><p><img src="https://img-blog.csdnimg.cn/20210217153729367.png" srcset="/img/loading.gif" lazyload alt="image-20210217153631429"></p>
<p><strong>编译时异常（受检异常）：异常必须要在编译（编写）阶段预先处理，如果不处理，编译器会报错，发生的概率较高。</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 运行出错</span><br><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>        <span class="hljs-comment">// main方法中调用doSome()方法</span><br>        <span class="hljs-comment">// 因为doSome()方法声明位置上有：throws ClassNotFoundException</span><br>        <span class="hljs-comment">// 我们在调用doSome()方法的时候必须对这种异常进行预先的处理。</span><br>        <span class="hljs-comment">// 如果不处理，编译器就报错。</span><br>        doSome();<span class="hljs-comment">//编译器报错信息： Unhandled exception: java.lang.ClassNotFoundException</span><br>    &#125;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * doSome方法在方法声明的位置上使用了：throws ClassNotFoundException</span><br><span class="hljs-comment">     * 这个代码表示doSome()方法在执行过程中，有可能会出现ClassNotFoundException异常。</span><br><span class="hljs-comment">     * 叫做类没找到异常。这个异常直接父类是：Exception，所以ClassNotFoundException属于编译时异常。</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@throws</span> ClassNotFoundException</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doSome</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> ClassNotFoundException</span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;doSome!!!!&quot;</span>);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><strong>运行时异常（未受检异常）：在编译阶段可以不处理，发生的概率较低。</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 运行出错</span><br><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>         <span class="hljs-comment">/*</span><br><span class="hljs-comment">        程序执行到此处发生了ArithmeticException异常，底层new了一个ArithmeticException异常对象，</span><br><span class="hljs-comment">        然后抛出了，由于是main方法调用了100 / 0，所以这个异常ArithmeticException抛给了main方法，</span><br><span class="hljs-comment">        main方法没有处理，将这个异常自动抛给了JVM，JVM最终终止程序的执行。</span><br><span class="hljs-comment"></span><br><span class="hljs-comment">        ArithmeticException 继承 RuntimeException，属于运行时异常。</span><br><span class="hljs-comment">        在编写程序阶段不需要对这种异常进行预先的处理。</span><br><span class="hljs-comment">         */</span><br>        System.out.println(<span class="hljs-number">100</span> / <span class="hljs-number">0</span>);<br><br>        <span class="hljs-comment">// 这里的HelloWorld没有输出，没有执行。</span><br>        System.out.println(<span class="hljs-string">&quot;Hello World!&quot;</span>);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="17-2-1-处理异常的两种方式"><a href="#17-2-1-处理异常的两种方式" class="headerlink" title="17.2.1 处理异常的两种方式"></a>17.2.1 处理异常的两种方式</h4><p>==对于编译时异常，一定要在编译阶段就处理掉。==</p>
<p><strong>第一种方式：在方法声明的位置上，使用 <code>throws</code> 关键字，将异常抛给上一级。</strong>（<strong>谁调用我，我就抛给谁</strong>）</p>
<blockquote>
<p>但是异常上抛之后，方法调用者还是需要对这个异常进行处理，可以选择上抛或直接处理。</p>
</blockquote>
<blockquote>
<p>当异常一直上抛，最后抛给了 mian 方法，main 方法继续上抛，抛给了 jvm 虚拟机，jvm 知道这个异常发生，最后只能终止 java 程序的运行。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-comment">// 一般不建议在main方法上上抛异常，因为如果异常真正发生了，一定会抛给jvm虚拟机，jvm只有终止程序</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> ClassNotFoundException </span>&#123;<br>        <span class="hljs-comment">// 将异常上抛，如果没有出现异常，程序正常执行，出现问题，jvm 直接终止程序运行</span><br>        doSome();<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doSome</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> ClassNotFoundException</span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;doSome!!!!&quot;</span>);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><strong>第二种方式：在方法体内，使用 <code>try...catch</code> 语句进行异常的捕捉。</strong>（<strong>这件事情发生了，但我自己解决了，谁也不知道</strong>）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>        <span class="hljs-comment">// 使用 try...catch 语句进行异常捕捉</span><br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-comment">// 尝试调用方法，如果没有出现异常，不会进入 catch 语句块</span><br>            doSome();<br>        &#125; <span class="hljs-keyword">catch</span> (ClassNotFoundException e) &#123;<span class="hljs-comment">// 这里的引用 e 中保存的是之前 new 出来的异常对象的内存地址</span><br>            <span class="hljs-comment">// 如果出现异常，进入 catch 语句块</span><br>            <span class="hljs-comment">// 捕捉异常</span><br>            <span class="hljs-comment">// 以下程序是打印异常堆栈追踪信息</span><br>            e.printStackTrace();<br>        &#125;<br>    &#125;<br><br>    <span class="hljs-comment">// 如果出现异常，会在底层 new 一个 ClassNotFoundException 异常对象，并且上抛</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doSome</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> ClassNotFoundException</span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;doSome!!!!&quot;</span>);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>



<h3 id="17-3-异常的上抛和捕捉"><a href="#17-3-异常的上抛和捕捉" class="headerlink" title="17.3 异常的上抛和捕捉"></a>17.3 异常的上抛和捕捉</h3><h4 id="17-3-1-上抛"><a href="#17-3-1-上抛" class="headerlink" title="17.3.1 上抛"></a>17.3.1 上抛</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.io.FileInputStream;<br><span class="hljs-keyword">import</span> java.io.FileNotFoundException;<br><br><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-comment">// 一般不建议在main方法上上抛异常，因为如果异常真正发生了，一定会抛给jvm虚拟机，jvm只有终止程序</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;main begin&quot;</span>);<br>        <span class="hljs-comment">// 不建议在main方法上上抛异常，所以在这里捕捉异常</span><br>        <span class="hljs-keyword">try</span> &#123;<br>            m1();<br>        &#125; <span class="hljs-keyword">catch</span> (FileNotFoundException e) &#123;<br>            System.out.println(<span class="hljs-string">&quot;文件不存在！&quot;</span>);<br>        &#125;<br>        System.out.println(<span class="hljs-string">&quot;main over&quot;</span>);<br>    &#125;<br><br>    <span class="hljs-comment">// 继续上抛</span><br>    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">m1</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> FileNotFoundException </span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;m1 begin&quot;</span>);<br>        m2();<br>        System.out.println(<span class="hljs-string">&quot;m1 over&quot;</span>);<br>    &#125;<br><br>    <span class="hljs-comment">// 异常上抛，可以上抛具体异常，也可以上抛父类异常，如 FileNotFoundException 的父类就是 IOException</span><br>    <span class="hljs-comment">// private static void m2() throws IOException &#123;</span><br>    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">m2</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> FileNotFoundException </span>&#123;<br>        System.out.println(<span class="hljs-string">&quot;m2 begin&quot;</span>);<br>        <span class="hljs-comment">// 会出现异常，选择上抛</span><br>        <span class="hljs-keyword">new</span> FileInputStream(<span class="hljs-string">&quot;D:\\Code\\Kotlin\\Day01\\Kotlin01\\src\\com\\Person.kt&quot;</span>);<br>        System.out.println(<span class="hljs-string">&quot;m2 over&quot;</span>);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>如果异常没有发生：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 输出：</span><br>	main begin<br>    m1 begin<br>    m2 begin<br>    m2 over<br>    m1 over <br>    main over<br></code></pre></td></tr></table></figure>

<ul>
<li>如果发生了异常：</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 输出：</span><br>	main begin<br>    m1 begin<br>    m2 begin<br>    文件不存在！<br>    main over<br></code></pre></td></tr></table></figure>

<h4 id="17-3-2-捕捉"><a href="#17-3-2-捕捉" class="headerlink" title="17.3.2 捕捉"></a>17.3.2 捕捉</h4><blockquote>
<p>catch后面的小括号中的类型可以是具体的异常类型，也可以是该异常类型的父类型。</p>
<p>catch可以写多个。建议catch的时候，精确的一个一个处理。这样有利于程序的调试。</p>
<p>catch写多个的时候，从上到下，必须遵守从小到大。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.io.FileInputStream;<br><span class="hljs-keyword">import</span> java.io.FileNotFoundException;<br><br><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>        <span class="hljs-comment">// 使用 try...catch 语句来进行异常的捕捉</span><br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-comment">//  会出现文件未发现异常</span><br>            FileInputStream fileInputStream = <span class="hljs-keyword">new</span> FileInputStream(<span class="hljs-string">&quot;D:\\Code\\Kotlin\\Day01\\Kotlin01\\src\\com\\Person.kt&quot;</span>);<br>            <span class="hljs-comment">// 会出现计算异常</span><br>            System.out.println(<span class="hljs-number">100</span> / <span class="hljs-number">0</span>);<br>        &#125; <span class="hljs-keyword">catch</span> (FileNotFoundException | ArithmeticException e) &#123;<span class="hljs-comment">// 这里可以捕捉具体的异常，也可以捕捉父类异常</span><br>            <span class="hljs-comment">// FileNotFoundException | ArithmeticException e 是 JDK8 新特性</span><br>            <span class="hljs-keyword">if</span> (e <span class="hljs-keyword">instanceof</span> FileNotFoundException) &#123;<br>                System.out.println(<span class="hljs-string">&quot;文件没有找到&quot;</span>);<br>            &#125; <span class="hljs-keyword">else</span> &#123;<br>                System.out.println(<span class="hljs-string">&quot;除数不能为 0&quot;</span>);<br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="17-3-3-上抛和捕捉的选择"><a href="#17-3-3-上抛和捕捉的选择" class="headerlink" title="17.3.3 上抛和捕捉的选择"></a>17.3.3 上抛和捕捉的选择</h4><p><strong>==如果希望调用者来处理异常，就 throws 上报==，其他情况使用 try … catch 捕捉</strong></p>
<h3 id="17-4-异常对象的常用方法"><a href="#17-4-异常对象的常用方法" class="headerlink" title="17.4 异常对象的常用方法"></a>17.4 异常对象的常用方法</h3><ol>
<li><strong>获取异常的简单描述信息：</strong><code>String msg = exception.getMessage();</code> </li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java">NullPointerException nullPointerException = <span class="hljs-keyword">new</span> NullPointerException(<span class="hljs-string">&quot;空指针异常！&quot;</span>);<br><span class="hljs-comment">// 获取异常的简单描述信息</span><br>String msg = nullPointerException.getMessage();<br>System.out.println(msg);<span class="hljs-comment">// 输出：空指针异常！</span><br></code></pre></td></tr></table></figure>

<ol start="2">
<li><strong>打印异常追踪的堆栈信息</strong>：<code>exception.printStackTrace();</code></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java">NullPointerException nullPointerException = <span class="hljs-keyword">new</span> NullPointerException(<span class="hljs-string">&quot;空指针异常！&quot;</span>);<br><span class="hljs-comment">// java 后台打印异常追踪信息的时候，采用了异步线程的方式打印</span><br>nullPointerException.printStackTrace();<br></code></pre></td></tr></table></figure>

<p><strong>异常追踪信息怎么看：</strong></p>
<p>​    从上往下一行一行看，但是要注意的是，sun 公司写好的代码就不用看了，只要的问题是在自己编写的代码上。</p>
<h3 id="17-5-关于try-catch中的finally子句"><a href="#17-5-关于try-catch中的finally子句" class="headerlink" title="17.5 关于try..catch中的finally子句"></a>17.5 关于try..catch中的finally子句</h3><ul>
<li><p><strong>在finally子句中的代码是最后执行的，并且是一定会执行的</strong>，即使try语句块中的代码出现了异常。</p>
</li>
<li><p>finally子句必须和try一起出现，不能单独编写。</p>
</li>
<li><p>finally语句通常使用在哪些情况下呢？</p>
<ul>
<li><strong>通常在finally语句块中完成资源的释放/关闭</strong>。（保证代码一定执行）</li>
</ul>
</li>
<li><p>try…finally （没有 catch）可以连用</p>
</li>
<li><p><strong>finally 语句块中的代码会在 return 前执行</strong></p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">try</span> &#123;<br>    System.out.println(<span class="hljs-string">&quot;try...&quot;</span>);<br>    <span class="hljs-keyword">return</span>;<br>&#125; <span class="hljs-keyword">finally</span> &#123;<br>    <span class="hljs-comment">// finally中的语句会执行。能执行到。</span><br>    System.out.println(<span class="hljs-string">&quot;finally...&quot;</span>);<br>&#125;<br><span class="hljs-comment">/*</span><br><span class="hljs-comment">	输出：</span><br><span class="hljs-comment">		try...</span><br><span class="hljs-comment">        finally...</span><br><span class="hljs-comment">*/</span><br></code></pre></td></tr></table></figure>

<ul>
<li><strong>如果退出 JVM，finally语句块中的代码不执行</strong></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">try</span> &#123;<br>    System.out.println(<span class="hljs-string">&quot;try...&quot;</span>);<br>    <span class="hljs-comment">// 退出 JVM</span><br>    System.exit(<span class="hljs-number">0</span>);<br>&#125; <span class="hljs-keyword">finally</span> &#123;<br>    System.out.println(<span class="hljs-string">&quot;finally...&quot;</span>);<br>&#125;<br><span class="hljs-comment">/*</span><br><span class="hljs-comment">	输出：</span><br><span class="hljs-comment">		try...</span><br><span class="hljs-comment">*/</span><br></code></pre></td></tr></table></figure>

<ul>
<li>==面试题== : 最后的结果输出为 100</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>        <span class="hljs-keyword">int</span> result = m();<br>        System.out.println(result);<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">m</span><span class="hljs-params">()</span> </span>&#123;<br>        <span class="hljs-keyword">int</span> i = <span class="hljs-number">100</span>;<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-comment">// 这行代码出现在 i = 100 之后，所以最终的返回值必须是 100</span><br>            <span class="hljs-comment">// 但是return 语句还必须保证是最后执行的，一旦执行，整个方法结束。</span><br>            <span class="hljs-comment">// 可以从反编译的程序来看出执行顺序</span><br>            <span class="hljs-keyword">return</span> i;<br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            i++;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java">java语法规则（有一些规则是不能破坏的，一旦这么说了，就必须这么做！）：<br>    java中有一条这样的规则：<br>        方法体中的代码必须遵循自上而下顺序依次逐行执行（亘古不变的语法！）<br>    java中海油一条语法规则：<br>        <span class="hljs-keyword">return</span>语句一旦执行，整个方法必须结束（亘古不变的语法！）<br></code></pre></td></tr></table></figure>

<p>反编译结果：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test01</span> </span>&#123;<br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Test01</span><span class="hljs-params">()</span> </span>&#123;<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>&#123;<br>        <span class="hljs-keyword">int</span> result = m();<br>        System.out.println(result);<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">m</span><span class="hljs-params">()</span> </span>&#123;<br>        <span class="hljs-keyword">byte</span> i = <span class="hljs-number">100</span>;<br><br>        <span class="hljs-keyword">byte</span> var1;<br>        <span class="hljs-keyword">try</span> &#123;<br>            var1 = i;<br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">int</span> var5 = i + <span class="hljs-number">1</span>;<br>        &#125;<br><br>        <span class="hljs-keyword">return</span> var1;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>



<h3 id="17-6-自定义异常"><a href="#17-6-自定义异常" class="headerlink" title="17.6 自定义异常"></a>17.6 自定义异常</h3><p>第一步：编写一个类继承 Exception 或者 RunTimeException。</p>
<p>第二步：提供两个构造方法，一个无参数，一个带有 String 参数的。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyException</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Exception</span> </span>&#123;<span class="hljs-comment">// 编译时异常</span><br>    <span class="hljs-comment">// 无参构造方法</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyException</span><span class="hljs-params">()</span> </span>&#123;<br>        <span class="hljs-comment">// 默认有一个 super()</span><br>    &#125;<br>    <br>    <span class="hljs-comment">// 有参构造方法</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyException</span><span class="hljs-params">(String s)</span> </span>&#123;<br>        <span class="hljs-keyword">super</span>(s);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyException</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">RunTimeException</span> </span>&#123;<span class="hljs-comment">// 运行时异常</span><br>    <span class="hljs-comment">// 无参构造方法</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyException</span><span class="hljs-params">()</span> </span>&#123;<br>        <span class="hljs-comment">// 默认有一个 super()</span><br>    &#125;<br>    <br>    <span class="hljs-comment">// 有参构造方法</span><br>    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">MyException</span><span class="hljs-params">(String s)</span> </span>&#123;<br>        <span class="hljs-keyword">super</span>(s);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>



<h3 id="17-7-方法覆盖与异常"><a href="#17-7-方法覆盖与异常" class="headerlink" title="17.7 方法覆盖与异常"></a>17.7 方法覆盖与异常</h3><p><strong>重写之后的方法不能比重写之前的方法抛出更多的异常</strong></p>
<p>==tips：父类方法不抛异常，子类可以抛RunTimeException==</p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/Java-%E5%9F%BA%E7%A1%80/">Java 基础</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Java-%E5%9F%BA%E7%A1%80/">Java 基础</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/09/13/Java%E5%9F%BA%E7%A1%80-2021-09-13-%E9%9B%86%E5%90%88/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">18、集合</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/09/13/Java%E5%9F%BA%E7%A1%80-2021-09-13-%E5%B8%B8%E7%94%A8%E7%B1%BB/">
                        <span class="hidden-mobile">16、常用类</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.3/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.1/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js" ></script>



  <script  src="/js/local-search.js" ></script>






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.12/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>














  
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxuehua.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/caidai.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/love.js"></script>
<script src="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<script src="//cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script>



<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>

  <!--动态线条背景-->
  <script type="text/javascript" color="70,119,184" opacity='1' zIndex="-2" count="200" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"left","width":200,"height":400},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
